import {
	defineStore
} from "pinia"
import {
	getHouseData,
	getStallData,
	getVehicleData,
	getCollectData,
	getMessageData,
	getLoginData,
	getRentData,
	getGuestData,
	getAddVehicleData,
	getAgainRent,
	getOutRent,
	getGuestDetailData
} from "../api/myData.js"
export const useMyStore = defineStore("my", {
	state: () => ({
		house: [],
		stall: [],
		vehicle: [],
		collect: [],
		message: [],
		account: {},
		rent: [],
		guest: [],
		logger: [],
		guestDetail:{}
	}),
	actions: {
		// 我的房屋数据
		async getHouse() {
			try {
				const res = await getHouseData()
				this.house = res.data
			} catch (error) {
				console.log(error)
			}
		},
		// 我的车位数据
		async getStall() {
			try {
				const res = await getStallData()
				this.stall = res.data
			} catch (error) {
				console.log(error)
			}
		},
		// 我的车辆数据
		async getVehicle() {
			try {
				const res = await getVehicleData()
				this.vehicle = res.data
			} catch (error) {
				console.log(error)
			}
		},
		// 添加车辆
		async getAddVehicle(data) {
			try {
				await getAddVehicleData(data)
				this.getVehicle()
			} catch (error) {
				console.log(error)
			}
		},
		// 我的收藏数据
		async getCollect() {
			try {
				const res = await getCollectData()
				this.collect = res.data
			} catch (error) {
				console.log(error)
			}
		},
		// 消息通知数据
		async getMessage() {
			try {
				const res = await getMessageData()
				this.message = res.data
			} catch (error) {
				console.log(error)
			}
		},
		// 登录数据
		async getLogin() {
			try {
				const res = await getLoginData()
				this.account = res.data[0]
			} catch (error) {
				console.log(error)
			}
		},
		// 我的租房数据
		async getRent() {
			try {
				const res = await getRentData()
				this.rent = res.data
			} catch (error) {
				console.log(error)
			}
		},
		// 下架房屋
		async getOut(data) {
			try {
				await getAgainRent(data)
				this.getRent()
			} catch (error) {
				console.log(error)
			}
		},
		// 重新上架房屋
		async getAgain(data) {
			try {
				await getAgainRent(data)
				this.getRent()
			} catch (error) {
				console.log(error)
			}
		},
		// 访客记录数据
		async getGuest() {
			try {
				const res = await getGuestData()
				this.guest = res.data
			} catch (error) {
				console.log(error)
			}
		},
		// 访客详情
		async getGuestDetail(id) {
			try {
				const res = await getGuestDetailData(id)
				this.guestDetail=res.data[0]
			} catch (error) {
				console.log(error)
			}
		}
	}
})